﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NCRGEA
{
    public partial class frmMain : Form
    {
        public AAL.User CurrentUser {get; set;}

        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            this.Text += " - " +  Application.ProductVersion;
            DisableMenuItems();
            UtilityForms.frmLogin fLogin = new UtilityForms.frmLogin() { MdiParent = this };
            fLogin.Show();
        }

        private void DisableMenuItems()
        {
            membersToolStripMenuItem.Enabled = false;
            adminToolStripMenuItem.Enabled = false;
            paymentsToolStripMenuItem.Enabled = false;
            reportsToolStripMenuItem.Enabled = false;
            windowsToolStripMenuItem.Enabled = false;
        }

        public void LogIn(AAL.User currentUser)
        {
            this.CurrentUser = currentUser;
            membersToolStripMenuItem.Enabled = true;
            adminToolStripMenuItem.Enabled = true;
            paymentsToolStripMenuItem.Enabled = true;
            reportsToolStripMenuItem.Enabled = true;
            windowsToolStripMenuItem.Enabled = true;
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void addMembersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Members.frmAddMembers fAddMembers = new Members.frmAddMembers();
            LaunchForm(fAddMembers);
        }

        /// <summary>
        /// Sets each forms Parent For to MidiParent and shows the form.
        /// </summary>
        /// <param name="theForm"></param>
        public void LaunchForm(Form theForm)
        {
            bool allow = false;
            if (theForm is Reports.frmGroupReport)
                allow = true;
            if (theForm is Reports.frmTypeReport)
                allow = true;
            if (theForm is Members.frmViewMember)
                allow = true;

            if(!allow)
                foreach (Form f in MdiChildren)
                {
                    if (f.GetType() == theForm.GetType())
                    {
                        f.BringToFront();
                        f.Focus();
                        return;
                    }
                }

            theForm.MdiParent = this;
            theForm.Show();
        }

        /// <summary>
        /// Loads the Quick Search Screen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void quickSearchToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Members.frmQuickSearch fAddMembers = new Members.frmQuickSearch();
            LaunchForm(fAddMembers);
        }

        /// <summary>
        /// Loads the Manage Accounts screen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void manageAccountsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Admin.frmManageAccounts fManageAccounts = new Admin.frmManageAccounts();
            LaunchForm(fManageAccounts);
        }

        /// <summary>
        /// Loads the Full Query Screen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fullQueryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Members.frmFullQuery fFullQuery = new Members.frmFullQuery();
            LaunchForm(fFullQuery);
        }

        private void convert90ToFreeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Admin.frmConvert90ToFree fConvert90 = new Admin.frmConvert90ToFree();
            LaunchForm(fConvert90);
        }

        private void addPaymentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Payments.frmBarcodeEntry fBarCodeEntry = new Payments.frmBarcodeEntry();
            LaunchForm(fBarCodeEntry);
        }

        private void importMembersToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Admin.frmNewMemberImport fNewMemberImport = new Admin.frmNewMemberImport();
            LaunchForm(fNewMemberImport);
        }

        private void exportDeductionsToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Admin.frmExportDeductions fExportDeduction = new Admin.frmExportDeductions();
            LaunchForm(fExportDeduction);
        }

        private void prospectiveMembersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmTypeReport fReportViewer = new Reports.frmTypeReport(2);
            LaunchForm(fReportViewer);
        }

        private void activeMembersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmTypeReport fReportViewer = new Reports.frmTypeReport(1);
            LaunchForm(fReportViewer);
        }

        private void freeMembersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmTypeReport fReportViewer = new Reports.frmTypeReport(3);
            LaunchForm(fReportViewer);
        }

        private void lifetimeMembersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmTypeReport fReportViewer = new Reports.frmTypeReport(4);
            LaunchForm(fReportViewer);
        }

        private void overdueMembersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmTypeReport fReportViewer = new Reports.frmTypeReport(7);
            LaunchForm(fReportViewer);
        }

        private void deceasedMembersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmTypeReport fReportViewer = new Reports.frmTypeReport(9);
            LaunchForm(fReportViewer);
        }

        private void stateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmGroupReport fReportViewer = new Reports.frmGroupReport(1);
            LaunchForm(fReportViewer);
        }

        private void nationalGuardToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmGroupReport fReportViewer = new Reports.frmGroupReport(2);
            LaunchForm(fReportViewer);
        }

        private void localToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmGroupReport fReportViewer = new Reports.frmGroupReport(3);
            LaunchForm(fReportViewer);
        }

        private void registerOfDeedsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmGroupReport fReportViewer = new Reports.frmGroupReport(4);
            LaunchForm(fReportViewer);
        }

        private void judicialToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmGroupReport fReportViewer = new Reports.frmGroupReport(5);
            LaunchForm(fReportViewer);
        }

        private void legislativeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmGroupReport fReportViewer = new Reports.frmGroupReport(6);
            LaunchForm(fReportViewer);
        }

        private void disabilityToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmGroupReport fReportViewer = new Reports.frmGroupReport(7);
            LaunchForm(fReportViewer);
        }

        private void legislativeFundToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmGroupReport fReportViewer = new Reports.frmGroupReport(8);
            LaunchForm(fReportViewer);
        }

        private void fireToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmGroupReport fReportViewer = new Reports.frmGroupReport(9);
            LaunchForm(fReportViewer);
        }

        private void spouseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmTypeReport fReportViewer = new Reports.frmTypeReport(6);
            LaunchForm(fReportViewer);
        }

        private void inactiveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmTypeReport fReportViewer = new Reports.frmTypeReport(8);
            LaunchForm(fReportViewer);
        }

        private void removedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Reports.frmTypeReport fReportViewer = new Reports.frmTypeReport(5);
            LaunchForm(fReportViewer);
        }

        private void exportVisionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Admin.frmExportVision fExportVision= new Admin.frmExportVision();
                LaunchForm(fExportVision);
        }

        private void exportDentalToolStripMenuItem_Click(object sender, EventArgs e)
        {
             Admin.frmExportDental fExportDental= new Admin.frmExportDental();
                  LaunchForm(fExportDental);
        }

        private void importErrorListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Admin.frmImportErrorList fImportError = new Admin.frmImportErrorList();
            LaunchForm(fImportError);
        } 
    }
}
